<?php
/**
* Profiler class file.
*
* @author Federico Ramirez <fedekiller@gmail.com>
* @link http://code.google.com/p/akaikiwi/
* @copyright Copyright &copy; 2008-2011 Federico Ramirez
* @license http://www.opensource.org/licenses/mit-license.php MIT Licence
*/

/*
* This class will show useful information for debugging purposes
*/
class Profiler {

	/**
	 * Returns the profiler
	 */
	public function get() {
		$tpl = file_get_contents('akaikiwi/views/profiler.php');
		$trs = NULL;

		// Benchmarks
		$benchmark = AkaiKiwi::loadLib('Benchmark');
		$marks = $benchmark->get_marks();
		$trs .= '<tr><td><b>Benchmark marks</b></td><td></td></tr>';
		foreach($marks as $mark => $time) {
			$trs .= '<tr><td>- '.$mark.'</td><td>'.round($time, 3).'</td></tr>';
		}

		// POST
		$trs .= '<tr><td><b>POST requests</b></td><td></td></tr>';
		foreach($_POST as $k => $v) {
			$trs .= '<tr><td>- '.$k.'</td><td>'.$v.'</td></tr>';
		}

		// GETS
		$trs .= '<tr><td><b>GET requests</b></td><td></td></tr>';
		foreach($_GET as $k => $v) {
			$trs .= '<tr><td>- '.$k.'</td><td>'.$v.'</td></tr>';
		}

		// Memory usage
		$trs .= '<tr><td><b>Memory usage</b></td><td>'.round(memory_get_usage() / 1024, 3).' kb</td></tr>';
		
		// Execution time
		$trs .= '<tr><td><b>Execution time</b></td><td>'.$benchmark->get_time('app_init', 'app_end').' seconds</td></tr>';

		return str_replace('{tr}', $trs, $tpl);
	}
}
